//
//  DWPerson+associateObject.m
//  OCAPPDemo
//
//  Created by 杨冬武 on 2022/9/17.
//

#import "DWPerson+associateObject.h"
#import <objc/runtime.h>

@implementation DWPerson (associateObject)

- (void)printAge {
    NSLog(@"age = %lu", (unsigned long)self.age);
}

- (NSString *)name {
    return objc_getAssociatedObject(self, _cmd);
}

- (void)setName:(NSString *)name {
    objc_setAssociatedObject(self, @selector(name), name, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (int)weight {
    return [objc_getAssociatedObject(self, _cmd) intValue];
}

- (void)setWeight:(int)weight {
    objc_setAssociatedObject(self, @selector(weight), @(weight), OBJC_ASSOCIATION_ASSIGN);
}

@end
